﻿
//缓动类
var tween=function(newObj){
	this.speed=10;
	this.time=10;
	this.duration=50;
	this.type='into';
	var pro=this;
	pro=this.rewriteAtt(pro,newObj);
	this.show();
}
tween.prototype={
	min:0,loop:null
	,out:function(){}
	,into:function(t,b,c,d){return c*t/d + b;}
	,rewriteAtt:function(formerObj,newObj){
		for(var i in newObj){
			formerObj[i]=newObj[i];
		}
		return formerObj;
	}
	,show:function(){
		var pro=this;
		this.min=this[this.type](this.time,this.min,this.max-this.min,this.duration);
		this.callBack&&this.callBack(this.min);
		if(this.stopJudge()){
			clearTimeout(this.loop);
			this.lastCallBack&&this.lastCallBack();
			return;
		}
		this.loop=setTimeout(function(){pro.show()},this.speed);
	}
};
function showBox(o,min,max,att,duration){
	//var o=document.getElementById(id);
	var obj=o.style;
	//var att='width';
	duration=duration || 50;
	new tween({
		duration:duration
		,min:min//缓动初始值
		,max:max//缓动结束值
		,type:'into'//缓入(由快到慢)
		,callBack:function(min){//给对象赋值
			obj[att]=Math.round(min)+'px';
		}
		,stopJudge:function(){//判断 结束缓动
			return parseInt(obj[att])==this.max;
		}
	});

}



function overOpen(obj,min,max,type,openType){
	var base=ylBase;
	var nextObj=type?obj:base.reNextSibing(obj);
	overObj=nextObj;
	nextObj.style.display='block';
	new tween({
		min:min//缓动初始值
		,max:max//缓动结束值
		,type:'into'//缓入(由快到慢)
		,duration:100
		,callBack:function(min){//给对象赋值
			base.alpha(nextObj,min);
		}
		,stopJudge:function(){//判断 结束缓动
			return this.min==this.max;
		}
	});
}
function timeOut(){
	if(overObj && !overObj['open']){
		overObj.style.display='none';
		overObj['open']=false;
		overObj=null;
	}
}

function initSelect(type){
	var base=ylBase;
	base.cyc(base.className(document,'text select'),function(obj){
		
		var nextObj=base.reNextSibing(obj);
		obj.onmouseover=function(){this.focus();};
		obj.onfocus=function(){if(!nextObj['open']){
			if(!type){
				nextObj.style.margin='0px';
				var xy=base.offsetLT(obj);
				var parLeft=base.retParScrollLeft(nextObj);
				nextObj.style.left=(xy.x-parLeft)+'px';
				nextObj.style.top=(xy.y+obj.offsetHeight+2)+'px';	
			}
			overOpen(this,0,100);
		}}
		obj.onblur=function(){if(!nextObj['open'])timeOut();};		
		nextObj.onmouseover=function(){this['open']=true;};
		nextObj.onmouseout=function(){obj.focus();this['open']=false;};
		
		//nextObj.onclick=function(){obj.focus();}
	});
}
function selectClick(obj,id){
	ylBase.$(id).value=obj.innerHTML;
	overObj.style.display='none';
	overObj['open']=false;
}
function initSelect2(){
	var base=ylBase;
	base.cyc(base.className(document,'imgBtn'),function(obj){
		var nextObj=base.reNextSibing(obj);
		obj.onmouseover=function(){this.focus();};
		obj.onfocus=function(){if(!nextObj['open'])overOpen(this,0,100);}
		obj.onblur=function(){if(!nextObj['open'])timeOut();};		
		nextObj.onmouseover=function(){this['open']=true;};
		nextObj.onmouseout=function(){this['open']=false;};
		nextObj.onclick=function(){obj.focus();}
	});
}
